const e = require('express');
var express = require('express');
var router = express.Router();

let userServices = require("../src/services/userServices");

router.post('/login',async function(req, res, next) {
    // console.log(AAAA);
    let {username,pwd} = req.body;
    let result = await userServices.login(username,pwd);

    if(result){
        res.json({code:0,msg:"用户登录成功"})
    }else{
        res.json({code:1,msg:"用户名或者密码错误"})
    }
    })


router.post('/enroll', async function (req, res, next) {
    let {username,pwd} = req.body;
    let result = await userServices.enroll(username,pwd);
    if(result==null){
        res.json({code:1,msg:"用户名已存在,请换个名字"})
    }else{
        res.json({code:0,msg:"注册成功"})
    }
    })
   

    
    
    module.exports = router;
    